package com.aierkeji.call.cms.dao.jpa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.aierkeji.call.cms.dao.BaseJPADao;
import com.aierkeji.call.cms.entity.AkjCallClueHistroy;

public interface AkjCallClueHistroyDao extends BaseJPADao<AkjCallClueHistroy, Long> {

	@Query(value="select t.* from akj_call_clue_histroy t where clue_id=:clueId order by id desc limit 5",nativeQuery=true)
	List<AkjCallClueHistroy> findByClueId(@Param("clueId") Long clueId);

	
	@Modifying
	@Query(value = "delete from akj_call_clue_histroy where exists  (select 1 from (select t.id from akj_call_clue_histroy  t left join akj_call_clue c on t.clue_id = c.id join akj_call_user a"
			+ " on t.created_by = a.id where c.id is null and a.leader_id = :leaderId ) t1 where  akj_call_clue_histroy.id = t1.id)",nativeQuery = true)
	@Transactional
	int deleteClueHistroy(@Param("leaderId")Long leaderId);
}
